package com.rtx.api.bean;

import com.rtx.api.enums.ResponseCodeEnum;
import io.swagger.annotations.ApiModelProperty;

import java.util.HashMap;
import java.util.Map;

/**
 * api统一返回
 */
public class ApiResponse {

    @ApiModelProperty("返回数据")
    private Map<String,Object> data;

    @ApiModelProperty("响应消息")
    private String msg;

    @ApiModelProperty("响应码")
    private Integer code;


    public ApiResponse() {
    }

    public ApiResponse(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ApiResponse success(){
        return new ApiResponse(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg());
    }

    public static ApiResponse failed(){
        return new ApiResponse(ResponseCodeEnum.FAILED.getCode(),ResponseCodeEnum.FAILED.getMsg());
    }

    public ApiResponse code(Integer code){
        this.setCode(code);
        return this;
    }

    public ApiResponse msg(String msg){
        this.setMsg(msg);
        return this;
    }

    public ApiResponse data(String key,Object value){
        if(this.data == null){
            this.data = new HashMap<>();
        }
        this.data.put(key,value);
        return this;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
